package week_home_work02;

import java.util.Scanner;

/**
 * @author zdl
 * @date 2024/11/23
 */
public class Demo73 {
    public static void main(String[] args) {
        //实现一个猜数字游戏，限制最多猜测3次。
        int randomNum = (int)(Math.random()*10)+1;
        System.out.println(randomNum);
        Scanner sc = new Scanner(System.in);
        int count = 0;
        int guess = 0;
        while(guess != randomNum && count <= 3){
            System.out.println("请开始第"+(count+1)+"次猜数：");
            guess = sc.nextInt();
            count++;
            if (guess < randomNum){
                System.out.println("猜小了，还有"+(3-count)+"次机会!");
            }else if(guess > randomNum){
                System.out.println("猜大了，还有"+(3-count)+"次机会!");
            }else {
                System.out.println("恭喜猜对了");
                break;
            }
            if (count == 3){
                System.out.println("很遗憾，3次机会你都没有猜对！");
                break;
            }
        }

    }
}
